﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Vtron.HipcConfigurationTools.Core;
using Vtron.HipcConfigurationTools.Domain;

namespace Vtron.HipcConfigurationTools.Test
{
    /// <summary>
    /// 编解码板链接API接口测试
    /// </summary>
    [TestClass]
    public class EncodedDecodedConnectionAPIUnitTest
    {
        [TestInitialize]
        public void Init()
        {
            Utils.IP = "10.4.1.173";
            Utils.PORT = 5001;
        }

        /// <summary>
        /// 消息		解码端，web获取编码端分辨率
        /// ID	请求：0x8201 应答：0x8202
        /// 方向	解码 端->编码端
        /// 参数	HIPC_CMD_VIDEO_RESOLUTION_GET_REQ //获取分辨率请求
        /// HIPC_CMD_VIDEO_RESOLUTION_GET_RESP //获取分辨率应答
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;      //协议头
        ///     Int8    channel;     //  
        ///     Int8     type;             //0:DP，1：dual link
        ///     Int16   width;        //宽度
        ///     Int16   height;       //高度 
        /// }T_HIPC_VIDEO_RESOLUTION_REQ, T_HIPC_VIDEO_RESOLUTION_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_RESOLUTION_GET_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_RESOLUTION_REQ request = new T_HIPC_VIDEO_RESOLUTION_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8201 };
            T_HIPC_VIDEO_RESOLUTION_RESP response = handler.Handle<T_HIPC_VIDEO_RESOLUTION_RESP>(request);

            Assert.AreEqual(0x8202, response.head.msgType);
        }

        /// <summary>
        /// 消息		解码端，web连接视频请求
        /// ID	请求0x8203    应答 0x8204
        /// 方向	web，解码端->编码端，
        /// 参数	HIPC_CMD_VIDEO_CONNECT_STREAM_REQ //连接视频请求
        /// HIPC_CMD_ VIDEO_CONNECT_STREAM _RESP //连接视频应答
        /// Typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  channel;          //通道号
        ///     Uint8  ipAddress[20];    // 解码端自己的ip地址，后续如果有组播，则是组播地址。
        ///     Uint16  port;            //如果是tcp解码端使用该端口连接编码
        ///     Uint8  mode;            //视频发送方式 0:UDP组播 1: UDP 2: TCP 3:RTSP.
        /// } T_HIPC_VIDEO_CONNECT_REQ, T_HIPC_VIDEO_CONNECT_RESP;
        /// 注意：目前HIPC第一版的发送方式支持tcp和rtsp。
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_CONNECT_STREAM_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_CONNECT_REQ request = new T_HIPC_VIDEO_CONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8203 };
            T_HIPC_VIDEO_CONNECT_RESP response = handler.Handle<T_HIPC_VIDEO_CONNECT_RESP>(request);

            Assert.AreEqual(0x8204, response.head.msgType);
        }

        /// <summary>
        /// 消息		解码端，web断开视频请求
        /// ID	请求：0x8205     应答：0x8206
        /// 方向	Web，解码端->编码端，
        /// 参数	/**断开视频请求 */
        /// HIPC_CMD_VIDEO_DISCONNECT_STREAM_REQ //断开视频连接请求
        /// HIPC_CMD_VIDEO_DISCONNECT_STREAM_RESP//断开视频连接应答
        /// Typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        /// Uint8  channel;          //通道号
        /// Uint8  ipAddress [20];   //
        /// Uint16  port;            // 
        /// Uint8  mode;            //视频发送方式0:UDP组播 1: UDP 2: TCP 3:RTSP.
        /// }T_HIPC_VIDEO_DISCONNECT_REQ, T_HIPC_VIDEO_DISCONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_DISCONNECT_STREAM_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_DISCONNECT_REQ request = new T_HIPC_VIDEO_DISCONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8205 };
            T_HIPC_VIDEO_DISCONNECT_RESP response = handler.Handle<T_HIPC_VIDEO_DISCONNECT_RESP>(request);

            Assert.AreEqual(0x8206, response.head.msgType);
        }

        /// <summary>
        /// 消息		解码端，web请求I帧
        /// ID	请求：0x8207   应答：0x8208
        /// 方向	Web，解码端->编码端
        /// 参数	HIPC_CMD_VIDEO_I_FRAME_REQ //I帧请求
        /// HIPC_CMD_VIDEO_I_FRAME_RESP//I帧请求应答
        /// typedef struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8 channel;        
        /// }T_HIPC_VIDEO_I_FRAME_REQ,T_HIPC_VIDEO_I_FRAME_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_VIDEO_I_FRAME_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_VIDEO_I_FRAME_REQ request = new T_HIPC_VIDEO_I_FRAME_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8207 };
            T_HIPC_VIDEO_I_FRAME_RESP response = handler.Handle<T_HIPC_VIDEO_I_FRAME_RESP>(request);

            Assert.AreEqual(0x8208, response.head.msgType);
        }

        /// <summary>
        /// 消息		解码端，web请求音频数据
        /// ID	请求：0x8300应答：0x8301
        /// 方向	Web，解码端->编码端
        /// 参数	HIPC_CMD_AUDIO_CONNECT_STREAM_REQ //音频请求
        /// HIPC_CMD_AUDIO_CONNECT_STREAM_RESP//音频请求应答
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  channel;          //
        ///     Uint8  ipAddress[20];   //解码端自己的ip地址，后续如果有组播，则是组播地址。
        ///     Uint16  port;            //如果是tcp解码端使用该端口连接编码
        ///     Uint8  mode;          //视频发送方式 0:UDP组播 1: UDP 2: TCP 3:RTSP.
        /// } T_HIPC_AUDIO_CONNECT_REQ, T_HIPC_AUDIO_CONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_AUDIO_CONNECT_STREAM_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_AUDIO_CONNECT_REQ request = new T_HIPC_AUDIO_CONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8207 };
            T_HIPC_AUDIO_CONNECT_RESP response = handler.Handle<T_HIPC_AUDIO_CONNECT_RESP>(request);

            Assert.AreEqual(0x8208, response.head.msgType);
        }

        /// <summary>
        /// 消息		解码端，web断开音频数据
        /// ID	请求：0x8302应答：0x8303
        /// 方向	Web，解码端->编码端
        /// 参数	HIPC_CMD_AUDIO_DISCONNECT_STREAM_REQ //断开音频请求
        /// HIPC_CMD_AUDIO_DISCONNECT_STREAM_RESP//断开音频请求应答
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        ///     Uint8  channel;          //
        ///     Uint8  ipAddress[20];   //解码端自己的ip地址，后续如果有组播，则是组播地址。
        ///     Uint16  port;            //如果是tcp解码端使用该端口连接编码
        ///     Uint8  mode;          //视频发送方式 0:UDP组播 1: UDP 2: TCP 3:RTSP.
        /// } T_HIPC_AUDIO_DISCONNECT_REQ, T_HIPC_AUDIO_DISCONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_AUDIO_DISCONNECT_STREAM_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_AUDIO_DISCONNECT_REQ request = new T_HIPC_AUDIO_DISCONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8302 };
            T_HIPC_AUDIO_DISCONNECT_RESP response = handler.Handle<T_HIPC_AUDIO_DISCONNECT_RESP>(request);

            Assert.AreEqual(0x8303, response.head.msgType);
        }

        /// <summary>
        /// 消息		解码端，Vwas连接KVM 
        /// ID	请求：0x8304应答：0x8305
        /// 方向	Vwas，解码端->编码端
        /// 参数	HIPC_CMD_USB_CONNECT_REQ //KVM连接请求
        /// HIPC_CMD_USB_CONNECT_RESP//KVM连接应答
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        /// } T_HIPC_USB_CONNECT_REQ, T_HIPC_USB_CONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_USB_CONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_USB_CONNECT_REQ request = new T_HIPC_USB_CONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8304 };
            T_HIPC_USB_CONNECT_RESP response = handler.Handle<T_HIPC_USB_CONNECT_RESP>(request);

            Assert.AreEqual(0x8305, response.head.msgType);
        }

        /// <summary>
        /// 消息		解码端，Vwas断开KVM
        /// ID	请求：0x8306应答：0x8307
        /// 方向	Vwas，解码端->编码端
        /// 参数	HIPC_CMD_USB_DISCONNECT_REQ //KVM断开请求
        /// HIPC_CMD_USB_DISCONNECT_RESP//KVM断开应答
        /// typedef  struct
        /// {
        ///     T_HIPC_NET_HEADER	   head;
        /// } T_HIPC_USB_DISCONNECT_REQ, T_HIPC_USB_DISCONNECT_RESP;
        /// </summary>
        [TestMethod]
        public void HIPC_CMD_USB_DISCONNECT_Test()
        {
            SocketHandler handler = new SocketHandler();
            T_HIPC_USB_DISCONNECT_REQ request = new T_HIPC_USB_DISCONNECT_REQ();
            request.head = new T_HIPC_NET_HEADER() { msgType = 0x8306 };
            T_HIPC_USB_DISCONNECT_RESP response = handler.Handle<T_HIPC_USB_DISCONNECT_RESP>(request);

            Assert.AreEqual(0x8307, response.head.msgType);
        }
    }
}
